package Servlet;

import Service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张
 * Date: 2025-03-08
 * Time: 11:51
 */
//删除用户 -- 群删
@WebServlet("/UserListDeleteServlet")
public class UserListDeleteServlet extends HttpServlet {
    private UserService userService = new UserService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf8");
        String[] userIds = req.getParameterValues("userIds");
        //实现批量删除逻辑 -- 根据用户userid进行删除
        boolean ok = userService.deleteByIdS(userIds);
        req.setAttribute("status", "success");
        if(ok) {
            req.setAttribute("status", "success");
            req.setAttribute("message", "删除成功,即将跳转至用户列表页面");
            req.setAttribute("redirectUrl", "UserList?pageNo=1");
            req.setAttribute("waitSeconds", 3);
        } else {
            req.setAttribute("status", "error");
            req.setAttribute("message", "删除失败,请检查数据库");
            req.setAttribute("redirectUrl", "UserList?pageNo=1");
            req.setAttribute("waitSeconds", 3);
        }
        req.getRequestDispatcher("skip.jsp").forward(req,resp);

    }
}
